package data

import (
	"fmt"

	"github.com/treelab/updatecolumn/models"
)

// getReferenceCellQuery return query
func getReferenceCellQuery(pageSize int, offset int) string {
	return fmt.Sprintf(`
		{
			recordReferenceColumns(func:eq(columnType, "RECORD_REFERENCE"), first:%d, offset:%d) {
				uid
				cells: has_cell {
					foreignRows: has_foreign_row {
						uid
					}
					uid
					rowId
				}
				symmetricColumnId
				symmetricColumns: has_symmetric_column {
					uid
				}
				lookupColumns: has_lookup_column {
					uid
				}
			}
		}
	`, pageSize, offset)
}

type ReferenceCellQueryResult struct {
	RecordReferenceColumns []models.Column
}

func getForeignCellsQuery(rowId string) string {
	return fmt.Sprintf(`
	{
		foreignRows(func:uid(%s)) {
			cells: has_cell {
				uid
				columnId
				columns: from_column {
					isDefault
				}
			}
		}
	}
	`, rowId)
}

type ForeignCellsResult struct {
	ForeignRows []models.Cell
}

// GetLookupCellsQuery by columnID
func GetLookupCellsQuery(columnId string) string {
	return fmt.Sprintf(`
	{
		lookupColumns(func:uid(%s)) {
			cells: has_cell {
				uid
				rowId
			}
		}
	}
	`, columnId)
}

type LookupCellsResult struct {
	LookupColumns []models.Column
}
